﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace jnxc.Web.ecshop
{
    public partial class slist : System.Web.UI.Page
    {
        BLL.product bll = new BLL.product();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string type = "";
                string name = "";
                string w = "";
                string t = "";
                int totalOrders = 0;
                if (Request.QueryString["type"] != null)
                {
                    type = Request.QueryString["type"].ToString();
                }
                if (Request.QueryString["t"] != null)
                {
                    t = Request.QueryString["t"].ToString();
                }
                if (Request.QueryString["name"] != null)
                {
                    name = Request.QueryString["name"];
                }
                if (type != "")
                {
                    if (type == "1") w = "plantname like '%" + name + "%'";
                    else w = "hname like '%" + name + "%'";
                    totalOrders = bll.GetRecordCountSearch(w);
                }
                else
                {
                    if (name != "")
                    {
                        w = "pname like '%" + name + "%'";
                        totalOrders = bll.GetRecordCount(w);

                    }
                    else
                    {
                        if (t != "")
                        {
                            if (t == "1") w = " pcname='物理防治'";
                            else if (t == "2") w = " pcname='生物防治'";
                            else if (t == "3") w = " pcname='化学防治'";
                            totalOrders = bll.GetRecordCount(w);
                        }
                    }

                }

                AspNetPager1.RecordCount = totalOrders;
                bindData();
            }

        }
        void bindData()
        {
            string type = "";
            string name = "";
            string t = "";
            if (Request.QueryString["type"] != null)
            {
                type = Request.QueryString["type"].ToString();
            }
            if (Request.QueryString["name"] != null)
            {
                name = Request.QueryString["name"];
            }
            if (Request.QueryString["t"] != null)
            {
                t = Request.QueryString["t"].ToString();
            }
            if (type != "")
            {
                string w = "";
                if (type == "1") w = "plantname like '%" + name + "%'";
                else w = "hname like '%" + name + "%'";
                rptl.DataSource = bll.GetListByPageSearch(w, "pid", AspNetPager1.StartRecordIndex, AspNetPager1.EndRecordIndex);
            }
            else
            {
                string w = "";
                if (name != "")
                {
                    w = "pname like '%" + name + "%'";
                }
                else
                {
                    if (t != "")
                    {
                        if (t == "1") w = " pcname='物理防治'";
                        else if (t == "2") w = " pcname='生物防治'";
                        else if (t == "3") w = " pcname='化学防治'";

                    }
                }
                rptl.DataSource = bll.GetListByPage(w, "pid", AspNetPager1.StartRecordIndex, AspNetPager1.EndRecordIndex);



            }
            rptl.DataBind();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            bindData();
        }
    }
}